load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("//bazel:tachyon_cc.bzl", "tachyon_cc_library")
load(
    "//tachyon/math/finite_fields/generator/ext_field_generator:build_defs.bzl",
    "generate_fp2s",
    "generate_fp3s",
)
load(
    "//tachyon/math/finite_fields/generator/prime_field_generator:build_defs.bzl",
    "SMALL_SUBGROUP_ADICITY",
    "generate_fft_prime_fields",
)

package(default_visibility = ["//visibility:public"])

string_flag(
    name = SMALL_SUBGROUP_ADICITY,
    build_setting_default = "3",
)

generate_fft_prime_fields(
    name = "gf7",
    testonly = True,
    class_name = "GF7",
    modulus = "7",
    namespace = "tachyon::math",
    reduce32 = "return static_cast<uint32_t>(v % ((1 << kModulusBits) - 1));",
    reduce64 = "return static_cast<uint32_t>(static_cast<uint32_t>(v) % ((1 << kModulusBits) - 1));",
    subgroup_generator = ":" + SMALL_SUBGROUP_ADICITY,
    use_montgomery = False,
)

generate_fp2s(
    name = "gf7_2",
    testonly = True,
    base_field = "GF7",
    base_field_hdr = "tachyon/math/finite_fields/test/gf7.h",
    class_name = "GF7_2",
    is_packed = False,
    namespace = "tachyon::math",
    non_residue = ["-1"],
    deps = [":gf7"],
)

generate_fp3s(
    name = "gf7_3",
    testonly = True,
    base_field = "GF7",
    base_field_hdr = "tachyon/math/finite_fields/test/gf7.h",
    class_name = "GF7_3",
    is_packed = False,
    namespace = "tachyon::math",
    non_residue = ["2"],
    deps = [":gf7"],
)

tachyon_cc_library(
    name = "finite_field_test",
    testonly = True,
    hdrs = ["finite_field_test.h"],
    deps = ["@com_google_googletest//:gtest"],
)
